package com.burstly.jackson.map;

import com.burstly.jackson.FormatSchema;
import com.burstly.jackson.JsonEncoding;
import com.burstly.jackson.JsonFactory;
import com.burstly.jackson.JsonGenerationException;
import com.burstly.jackson.JsonGenerator;
import com.burstly.jackson.PrettyPrinter;
import com.burstly.jackson.Version;
import com.burstly.jackson.Versioned;
import com.burstly.jackson.io.SegmentedStringWriter;
import com.burstly.jackson.map.ser.FilterProvider;
import com.burstly.jackson.map.type.TypeFactory;
import com.burstly.jackson.type.JavaType;
import com.burstly.jackson.type.TypeReference;
import com.burstly.jackson.util.ByteArrayBuilder;
import com.burstly.jackson.util.DefaultPrettyPrinter;
import com.burstly.jackson.util.MinimalPrettyPrinter;
import com.burstly.jackson.util.VersionUtil;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.text.DateFormat;

public class ObjectWriter
  implements Versioned
{
  protected static final PrettyPrinter NULL_PRETTY_PRINTER = new MinimalPrettyPrinter();
  protected final SerializationConfig _config;
  protected final JsonFactory _jsonFactory;
  protected final PrettyPrinter _prettyPrinter;
  protected final SerializerProvider _provider;
  protected final JavaType _rootType;
  protected final FormatSchema _schema;
  protected final SerializerFactory _serializerFactory;

  protected ObjectWriter(ObjectMapper paramObjectMapper, SerializationConfig paramSerializationConfig)
  {
    this._config = paramSerializationConfig;
    this._provider = paramObjectMapper._serializerProvider;
    this._serializerFactory = paramObjectMapper._serializerFactory;
    this._jsonFactory = paramObjectMapper._jsonFactory;
    this._rootType = null;
    this._prettyPrinter = null;
    this._schema = null;
  }

  protected ObjectWriter(ObjectMapper paramObjectMapper, SerializationConfig paramSerializationConfig, FormatSchema paramFormatSchema)
  {
    this._config = paramSerializationConfig;
    this._provider = paramObjectMapper._serializerProvider;
    this._serializerFactory = paramObjectMapper._serializerFactory;
    this._jsonFactory = paramObjectMapper._jsonFactory;
    this._rootType = null;
    this._prettyPrinter = null;
    this._schema = paramFormatSchema;
  }

  protected ObjectWriter(ObjectMapper paramObjectMapper, SerializationConfig paramSerializationConfig, JavaType paramJavaType, PrettyPrinter paramPrettyPrinter)
  {
    this._config = paramSerializationConfig;
    this._provider = paramObjectMapper._serializerProvider;
    this._serializerFactory = paramObjectMapper._serializerFactory;
    this._jsonFactory = paramObjectMapper._jsonFactory;
    this._rootType = paramJavaType;
    this._prettyPrinter = paramPrettyPrinter;
    this._schema = null;
  }

  protected ObjectWriter(ObjectWriter paramObjectWriter, SerializationConfig paramSerializationConfig)
  {
    this._config = paramSerializationConfig;
    this._provider = paramObjectWriter._provider;
    this._serializerFactory = paramObjectWriter._serializerFactory;
    this._jsonFactory = paramObjectWriter._jsonFactory;
    this._schema = paramObjectWriter._schema;
    this._rootType = paramObjectWriter._rootType;
    this._prettyPrinter = paramObjectWriter._prettyPrinter;
  }

  protected ObjectWriter(ObjectWriter paramObjectWriter, SerializationConfig paramSerializationConfig, JavaType paramJavaType, PrettyPrinter paramPrettyPrinter, FormatSchema paramFormatSchema)
  {
    this._config = paramSerializationConfig;
    this._provider = paramObjectWriter._provider;
    this._serializerFactory = paramObjectWriter._serializerFactory;
    this._jsonFactory = paramObjectWriter._jsonFactory;
    this._rootType = paramJavaType;
    this._prettyPrinter = paramPrettyPrinter;
    this._schema = paramFormatSchema;
  }

  private final void _configAndWriteCloseable(JsonGenerator paramJsonGenerator, Object paramObject, SerializationConfig paramSerializationConfig)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    Closeable localCloseable1 = (Closeable)paramObject;
    try
    {
      if (this._rootType == null)
      {
        this._provider.serializeValue(paramSerializationConfig, paramJsonGenerator, paramObject, this._serializerFactory);
        if (this._schema != null)
          paramJsonGenerator.setSchema(this._schema);
        JsonGenerator localJsonGenerator = paramJsonGenerator;
        paramJsonGenerator = null;
        localJsonGenerator.close();
        Closeable localCloseable2 = localCloseable1;
        localCloseable1 = null;
        localCloseable2.close();
        if (0 == 0);
      }
    }
    finally
    {
      try
      {
        null.close();
        if (0 == 0);
      }
      catch (IOException localIOException4)
      {
        try
        {
          while (true)
          {
            null.close();
            return;
            SerializerProvider localSerializerProvider = this._provider;
            JavaType localJavaType = this._rootType;
            SerializerFactory localSerializerFactory = this._serializerFactory;
            localSerializerProvider.serializeValue(paramSerializationConfig, paramJsonGenerator, paramObject, localJavaType, localSerializerFactory);
          }
          localObject = finally;
          if (paramJsonGenerator != null);
          try
          {
            paramJsonGenerator.close();
            if (localCloseable1 == null);
          }
          catch (IOException localIOException2)
          {
            try
            {
              localCloseable1.close();
              label140: throw localObject;
              localIOException2 = localIOException2;
            }
            catch (IOException localIOException1)
            {
              break label140;
            }
          }
          localIOException4 = localIOException4;
        }
        catch (IOException localIOException3)
        {
        }
      }
    }
  }

  private final void _writeCloseableValue(JsonGenerator paramJsonGenerator, Object paramObject, SerializationConfig paramSerializationConfig)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    Closeable localCloseable1 = (Closeable)paramObject;
    try
    {
      if (this._rootType == null)
      {
        this._provider.serializeValue(paramSerializationConfig, paramJsonGenerator, paramObject, this._serializerFactory);
        if (this._config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE))
          paramJsonGenerator.flush();
        Closeable localCloseable2 = localCloseable1;
        localCloseable1 = null;
        localCloseable2.close();
        if (0 == 0);
      }
    }
    finally
    {
      try
      {
        while (true)
        {
          null.close();
          return;
          this._provider.serializeValue(paramSerializationConfig, paramJsonGenerator, paramObject, this._rootType, this._serializerFactory);
        }
        localObject = finally;
        if (localCloseable1 != null);
        try
        {
          localCloseable1.close();
          label104: throw localObject;
        }
        catch (IOException localIOException1)
        {
          break label104;
        }
      }
      catch (IOException localIOException2)
      {
      }
    }
  }

  protected final void _configAndWriteValue(JsonGenerator paramJsonGenerator, Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    if (this._prettyPrinter != null)
    {
      PrettyPrinter localPrettyPrinter = this._prettyPrinter;
      if (localPrettyPrinter == NULL_PRETTY_PRINTER)
        localPrettyPrinter = null;
      paramJsonGenerator.setPrettyPrinter(localPrettyPrinter);
      if (this._schema != null)
        paramJsonGenerator.setSchema(this._schema);
      if ((!this._config.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE)) || (!(paramObject instanceof Closeable)))
        break label98;
      _configAndWriteCloseable(paramJsonGenerator, paramObject, this._config);
    }
    while (true)
    {
      return;
      if (!this._config.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT))
        break;
      paramJsonGenerator.useDefaultPrettyPrinter();
      break;
      label98: int i = 0;
      try
      {
        JavaType localJavaType = this._rootType;
        i = 0;
        if (localJavaType == null)
          this._provider.serializeValue(this._config, paramJsonGenerator, paramObject, this._serializerFactory);
        while (true)
        {
          i = 1;
          paramJsonGenerator.close();
          if (i != 0)
            break;
          try
          {
            paramJsonGenerator.close();
            return;
          }
          catch (IOException localIOException2)
          {
            return;
          }
          this._provider.serializeValue(this._config, paramJsonGenerator, paramObject, this._rootType, this._serializerFactory);
        }
      }
      finally
      {
        if (i != 0);
      }
    }
    try
    {
      paramJsonGenerator.close();
      label187: throw localObject;
    }
    catch (IOException localIOException1)
    {
      break label187;
    }
  }

  public boolean canSerialize(Class<?> paramClass)
  {
    return this._provider.hasSerializerFor(this._config, paramClass, this._serializerFactory);
  }

  public Version version()
  {
    return VersionUtil.versionFor(getClass());
  }

  public ObjectWriter withDateFormat(DateFormat paramDateFormat)
  {
    SerializationConfig localSerializationConfig = this._config.withDateFormat(paramDateFormat);
    if (localSerializationConfig == this._config)
      return this;
    return new ObjectWriter(this, localSerializationConfig);
  }

  public ObjectWriter withDefaultPrettyPrinter()
  {
    return withPrettyPrinter(new DefaultPrettyPrinter());
  }

  public ObjectWriter withFilters(FilterProvider paramFilterProvider)
  {
    if (paramFilterProvider == this._config.getFilterProvider())
      return this;
    return new ObjectWriter(this, this._config.withFilters(paramFilterProvider));
  }

  public ObjectWriter withPrettyPrinter(PrettyPrinter paramPrettyPrinter)
  {
    if (paramPrettyPrinter == this._prettyPrinter)
      return this;
    if (paramPrettyPrinter == null)
      paramPrettyPrinter = NULL_PRETTY_PRINTER;
    SerializationConfig localSerializationConfig = this._config;
    JavaType localJavaType = this._rootType;
    FormatSchema localFormatSchema = this._schema;
    return new ObjectWriter(this, localSerializationConfig, localJavaType, paramPrettyPrinter, localFormatSchema);
  }

  public ObjectWriter withSchema(FormatSchema paramFormatSchema)
  {
    if (this._schema == paramFormatSchema)
      return this;
    return new ObjectWriter(this, this._config, this._rootType, this._prettyPrinter, paramFormatSchema);
  }

  public ObjectWriter withType(JavaType paramJavaType)
  {
    if (paramJavaType == this._rootType)
      return this;
    return new ObjectWriter(this, this._config, paramJavaType, this._prettyPrinter, this._schema);
  }

  public ObjectWriter withType(TypeReference<?> paramTypeReference)
  {
    return withType(this._config.getTypeFactory().constructType(paramTypeReference.getType()));
  }

  public ObjectWriter withType(Class<?> paramClass)
  {
    return withType(this._config.constructType(paramClass));
  }

  public ObjectWriter withView(Class<?> paramClass)
  {
    if (paramClass == this._config.getSerializationView())
      return this;
    return new ObjectWriter(this, this._config.withView(paramClass));
  }

  public void writeValue(JsonGenerator paramJsonGenerator, Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    if ((this._config.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE)) && ((paramObject instanceof Closeable)))
      _writeCloseableValue(paramJsonGenerator, paramObject, this._config);
    while (true)
    {
      return;
      if (this._rootType == null)
        this._provider.serializeValue(this._config, paramJsonGenerator, paramObject, this._serializerFactory);
      while (this._config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE))
      {
        paramJsonGenerator.flush();
        return;
        this._provider.serializeValue(this._config, paramJsonGenerator, paramObject, this._rootType, this._serializerFactory);
      }
    }
  }

  public void writeValue(File paramFile, Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    _configAndWriteValue(this._jsonFactory.createJsonGenerator(paramFile, JsonEncoding.UTF8), paramObject);
  }

  public void writeValue(OutputStream paramOutputStream, Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    _configAndWriteValue(this._jsonFactory.createJsonGenerator(paramOutputStream, JsonEncoding.UTF8), paramObject);
  }

  public void writeValue(Writer paramWriter, Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    _configAndWriteValue(this._jsonFactory.createJsonGenerator(paramWriter), paramObject);
  }

  public byte[] writeValueAsBytes(Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    ByteArrayBuilder localByteArrayBuilder = new ByteArrayBuilder(this._jsonFactory._getBufferRecycler());
    _configAndWriteValue(this._jsonFactory.createJsonGenerator(localByteArrayBuilder, JsonEncoding.UTF8), paramObject);
    byte[] arrayOfByte = localByteArrayBuilder.toByteArray();
    localByteArrayBuilder.release();
    return arrayOfByte;
  }

  public String writeValueAsString(Object paramObject)
    throws IOException, JsonGenerationException, JsonMappingException
  {
    SegmentedStringWriter localSegmentedStringWriter = new SegmentedStringWriter(this._jsonFactory._getBufferRecycler());
    _configAndWriteValue(this._jsonFactory.createJsonGenerator(localSegmentedStringWriter), paramObject);
    return localSegmentedStringWriter.getAndClear();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.jackson.map.ObjectWriter
 * JD-Core Version:    0.6.2
 */